package lww231;

import org.apache.hadoop.io.WritableComparable;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
//没有实例化的属性不自动赋值 没有这个回报异常
@JsonIgnoreProperties(ignoreUnknown = true)
public class MovieInfo implements WritableComparable<MovieInfo> {
    private String title;       //电影名
    private int year;           //上映年份
    private String type;        //电影类型
    private float star;         //电影评分2-10分
    private String director;    //导演
    private String actor;       //演员
    private String time;        //电影时长
    private String film_page;   //电影信息连接

    @Override
    public String toString() {
        return "MovieInfo [title=" + title + ", year=" + year + ",type=" + type + ",star=" + star + ",director=" + director + ",actor=" + actor + ",time=" + time + ",film_page=" + film_page + "]";
    }

    @Override
    public int compareTo(MovieInfo o) {
        //首先按照star评分排序
        if (this.star > o.getStar()){
            return 1;
        }else if (this.star < o.getStar()){
            return -1;
        }
        //如果star评分相同，按照year年份排序
        if (this.year > o.getYear()){
            return 1;
        }else {
            return -1;
        }
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        //反序列化
        this.title = dataInput.readUTF();
        this.year = dataInput.readInt();
        this.type = dataInput.readUTF();
        this.star = dataInput.readFloat();
        this.director = dataInput.readUTF();
        this.actor = dataInput.readUTF();
        this.time = dataInput.readUTF();
        this.film_page = dataInput.readUTF();
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        //序列化
        dataOutput.writeUTF(this.title);
        dataOutput.writeInt(this.year);
        dataOutput.writeUTF(this.type);
        dataOutput.writeFloat(this.star);
        dataOutput.writeUTF(this.director);
        dataOutput.writeUTF(this.actor);
        dataOutput.writeUTF(this.time);
        dataOutput.writeUTF(this.film_page);
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public float getStar() {
        return star;
    }

    public void setStar(float star) {
        this.star = star;
    }

    public String getDirector() {
        return director;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    public String getActor() {
        return actor;
    }

    public void setActor(String actor) {
        this.actor = actor;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getFilm_page() {
        return film_page;
    }

    public void setFilm_page(String film_page) {
        this.film_page = film_page;
    }

    public void set(String title, int year, String type, float star, String director, String actor, String time, String film_page) {
        this.title = title;
        this.year = year;
        this.type = type;
        this.star = star;
        this.director = director;
        this.actor = actor;
        this.time = time;
        this.film_page = film_page;
    }
    public MovieInfo() {
        super();
        // TODO Auto-generated constructor stub
    }
    public MovieInfo(String title, int year, String type, float star, String director, String actor, String time, String film_page ) {
        super();
        this.title = title;
        this.year = year;
        this.type = type;
        this.star = star;
        this.director = director;
        this.actor = actor;
        this.time = time;
        this.film_page = film_page;
    }
    public void set(MovieInfo movieInfo) {
        // TODO Auto-generated method stub
        this.title = movieInfo.getTitle();
        this.year = movieInfo.getYear();
        this.type = movieInfo.getType();
        this.star = movieInfo.getStar();
        this.director = movieInfo.getDirector();
        this.actor = movieInfo.getActor();
        this.time = movieInfo.getTime();
        this.film_page = movieInfo.getFilm_page();
    }
}
